package thread;

public class JoinDemo {
    public static void main(String[] args) {
        System.out.println("写作业");
        Runnable r = new Runnable() {
            @Override
            public void run() {
                System.out.println("先吃饭");
                System.out.println("等我吃完再写");
                try {
                    Thread.sleep(1000);//线程睡眠1秒
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("吃完了");
            }
        };
        Thread eat = new Thread(r);
        eat.start();
        try {
            eat.join();//等待线程执行完毕
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("写作业");
    }
}
